#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time : 2021/9/12 14:52
# @Author : lenovo
# @Email : 26541796406@qq.com
# @File : addtask_page.py
# @Project : crm
"""任务添加页面"""
from selenium.webdriver.common.by import By
from page.base_page import BasePage
from utils.util import HS3
from selenium.webdriver.common.alert import Alert
class AddTask(BasePage):
    url = "{}/crm3/index.php?m=task&a=add".format(HS3)
    """定义定位器"""
    theme_locator = (By.NAME, 'subject')  # 主题输入框
    head_locator = (By.ID, "owner_name")  # 负责人输入框
    almost_locator = (By.XPATH, '/html/body/div[7]/div[2]/form/div/input')  # 负责人全选input
    choose_head_locator = (By.CSS_SELECTOR, 'input[rel="admin"]')  # 选择负责人
    ok_locator = (By.XPATH, '/html/body/div[7]/div[3]/div/button[1]')  # OK按钮
    director_locator = (By.ID, 'about_roles_name')  # 相关负责人输入框
    all_locator = (By.XPATH, '/html/body/div[8]/div[2]/form/div/input')  # 相关负责人全选input
    choose_director_locator = (By.CSS_SELECTOR, 'input[rel="wuyifan"]')  # 选择相关负责人
    determine_locator = (By.XPATH, '/html/body/div[8]/div[3]/div/button[1]/span')  # 确定按钮
    date_locator = (By.NAME, 'due_date')  # 截至日期
    describe_locator = (By.XPATH, '/html/body')  # 描述输入框
    submit_locator = (By.CSS_SELECTOR, 'input[value="保存"]')  # 保存按钮
    wrong_locator = (By.XPATH,'/html/body/div/form/fieldset/div[1]')  # 错误信息
    def input_theme(self,theme):
        """输入主题"""
        self.driver.find_element(*self.theme_locator).send_keys(theme)
    def clear_theme(self):
        """清除主题"""
        self.driver.find_element(*self.theme_locator).clear()
    def input_head(self):
        """选择负责人输入框"""
        self.driver.find_element(*self.head_locator).click()
    def input_choose_head(self):
        """选择负责人"""
        self.driver.find_element(*self.choose_head_locator).click()
    def ok(self):
        """选择负责人页面的OK"""
        self.driver.find_element(*self.ok_locator).click()
    def almost(self):
        """负责人全选input"""
        self.driver.find_element(*self.almost_locator).click()
    def input_director(self):
        """选择相关负责人输入框"""
        self.driver.find_element(*self.director_locator).click()
    def input_choose_director(self):
        """选择相关负责人"""
        self.driver.find_element(*self.choose_director_locator).click()
    def determine(self):
        """选择相关负责人页面的确定按钮"""
        self.driver.find_element(*self.determine_locator).click()
    def all(self):
        """选择相关负责人全选"""
        self.driver.find_element(*self.all_locator).click()
    def input_date(self,date):
        """输入截至日期"""
        self.driver.find_element(*self.date_locator).send_keys(date)
    def clear_date(self):
        """清除截止日期"""
        self.driver.find_element(*self.date_locator).clear()
    def input_frame(self):
        """切换到描述页面"""
        self.driver.switch_to.frame(self.driver.find_element_by_class_name('ke-edit-iframe'))
    def parent(self):
        """切换到最外层"""
        self.driver.switch_to.parent_frame()
    def input_describe(self,describe):
        """输入描述"""
        self.driver.find_element(*self.describe_locator).send_keys(describe)
    def clear_describe(self):
        """清除描述"""
        self.driver.find_element(*self.describe_locator).clear()
    def submit(self):
        """点击保存"""
        self.driver.find_element(*self.submit_locator).click()
    def get_wrong_txt(self):
        """获取参数错误"""
        return self.driver.find_element(*self.wrong_locator).text
    def txt_alert(self):
        """获取alert文本"""
        return Alert(self.driver).text

